import time

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(10)
# driver.get("https://demoqa.com/droppable")
#
# ac = ActionChains(driver, )
# draggable_ele = driver.find_element(By.ID, "draggable")
# droppable_ele = driver.find_element(By.ID, "droppable")

# ac.drag_and_drop(draggable_ele, droppable_ele)
# ac.click_and_hold(draggable_ele).move_to_element(droppable_ele).release()

# ac.drag_and_drop_by_offset(draggable_ele, 200, 0)
# ac.click_and_hold(draggable_ele).move_by_offset(200, 0).release()
# ac.click_and_hold(draggable_ele).move_to_element_with_offset(droppable_ele, 200, 0).release()



driver.get("https://demoqa.com/resizable")
driver.execute_script('window.scroll(0, document.body.scrollHeight)')
time.sleep(1)
# 注入 JavaScript 代码以显示鼠标位置
driver.execute_script("""
    // 创建一个小圆点的div元素
        const dot = document.createElement('div');
        dot.id = 'dot';

        // 使用JavaScript动态设置样式
        dot.style.position = 'absolute';
        dot.style.width = '20px';
        dot.style.height = '20px';
        dot.style.backgroundColor = 'red';
        dot.style.borderRadius = '50%'; // 使元素呈圆形
        dot.style.pointerEvents = 'none'; // 防止鼠标事件影响圆点

        // 将圆点元素添加到页面中
        document.body.appendChild(dot);

        // 监听鼠标移动事件
        document.addEventListener('mousemove', function(event) {
            // 获取鼠标位置
            const mouseX = event.pageX;
            const mouseY = event.pageY;

            // 设置圆点的位置
            dot.style.left = `${mouseX-10}px`;
            dot.style.top = `${mouseY-10}px`;
        });
""")




resizable_ele = driver.find_element(By.ID, 'resizable')
ac = ActionChains(driver)
ac.move_to_element_with_offset(resizable_ele, resizable_ele.size['width']/2-5, resizable_ele.size['height']/2-5)
ac.click_and_hold().move_by_offset(50, 50).release()
ac.perform()




# driver.get("https://demoqa.com/slider")
#
# range_ele = driver.find_element(By.XPATH, '//input[@type="range"]')
#
# ac = ActionChains(driver)
# # move_to_element  参考位置 中心
# ac.move_to_element_with_offset(range_ele, range_ele.size['width'] * 0.25 - range_ele.size['width'] / 2, 0)
# ac.click_and_hold()
# ac.perform()







input()
driver.quit()
